/*******************************************************************************
 * Homework 6 'ComparisonFinish' class implementation file
 * Author: Duncan Buell
 * Modified by: Andrew Shore, Wes Ring, JC Anderson, Colin Edwards
 * Date last modified: 5 April 2010
 *
 * This is simply a class to implement a comparison of 'Process'
 * instances.  In this case all we do is compare the execution
 * time to sort the queue using 'finishTime'. This class is used as the 
 * comparison class for the ready queue.
 *
 ******************************************************************************/
#include "ComparisonFinish.h"

/*******************************************************************************
 * Constructor.
 ******************************************************************************/
ComparisonFinish::ComparisonFinish()
{
}

/*******************************************************************************
 * Overloaded comparison operator () to compare two Process objects
 * Author: Andrew Shore, Wes Ring, JC Anderson, Colin Edwards
 * Date Last Modified: 5 April 2010
 *
 * This overloaded operator is used to compare two process objects to determine
 * where they are are placed in the ready queue. The ready queue is 
 * sorted based on finishTime and startTime is used as a tiebreaker. The
 * ready queue uses a min heap as opposed to a max heap so the finishTime
 * of elements increase as one moves further down the tree.
 *
 * Parameters: 
 * const Process& procOne - first proceess to be compared, const because we
 *                          don't want to change its value, passed by reference
 * const Process& procTwo - second process to be compared
 *
 * Output: none
 *
 * Returns: True if procOne has a greater finish time than procTwo,
 * False if procTwo has a greater finish time. If the finish times are equal
 * than the function returns true if procOne as a greater start time than
 * procTwo, and false if procTwo has the greater start time.
 *
 *****************************************************************************/ 
bool ComparisonFinish::operator() 
                 (const Process& procOne, const Process& procTwo) const{

  if( procOne.getFinishTime() > procTwo.getFinishTime() ){
    return true;
  }else if ( procOne.getFinishTime() < procTwo.getFinishTime() ){
    return false;
  }else{
    return (procOne.getStartTime() > procTwo.getStartTime());
  }
}
